package Manage;

import java.util.HashMap;
import java.util.Map;

public // 权限管理类
class PermissionManager {
    private Map<String, User> users = new HashMap<>();

    // 添加用户
    public void addUser(String username, String[] permissions) {
        User user = new User(username, permissions);
        users.put(username, user);
        System.out.println("用户 " + username + " 已添加");
    }

    // 删除用户
    public void removeUser(String username) {
        if (users.containsKey(username)) {
            users.remove(username);
            System.out.println("用户 " + username + " 已删除");
        } else {
            System.out.println("用户 " + username + " 不存在");
        }
    }

    // 分配权限
    public void assignPermissions(String username, String[] permissions) {
        if (users.containsKey(username)) {
            User user = users.get(username);
            user.setPermissions(permissions);
            System.out.println("用户 " + username + " 的权限已更新");
        } else {
            System.out.println("用户 " + username + " 不存在");
        }
    }

    // 查看用户权限
    public void viewPermissions(String username) {
        if (users.containsKey(username)) {
            User user = users.get(username);
            String[] permissions = user.getPermissions();
            System.out.println("用户 " + username + " 的权限:");
            for (String permission : permissions) {
                System.out.println("- " + permission);
            }
        } else {
            System.out.println("用户 " + username + " 不存在");
        }
    }
}
